package com.explorati.LeetCode203.removeElements;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 22:26 2020/9/20 0020
 * @ Description ：
 */
public class Solution1 {
    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }

    public ListNode removeElements(ListNode head, int val) {
        if(head == null) {
            return null;
        }

        ListNode dummyHead = new ListNode(0);
        dummyHead.next = head;

        ListNode pre = dummyHead;
        ListNode cur = head;
        while(cur != null) {
            if(cur.val == val) {
                pre.next = cur.next;
            }else {
                pre = pre.next;
            }
            cur = cur.next;
        }
        return dummyHead.next;
    }
}
